package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.SysUserShop;
import com.ruoyi.app.service.ISysUserShopService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户绑定店铺表Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/system/userShop")
public class SysUserShopController extends BaseController
{
    @Autowired
    private ISysUserShopService sysUserShopService;

    /**
     * 查询用户绑定店铺表列表
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserShop sysUserShop)
    {
        startPage();
        List<SysUserShop> list = sysUserShopService.selectSysUserShopList(sysUserShop);
        return getDataTable(list);
    }

    /**
     * 导出用户绑定店铺表列表
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:export')")
    @Log(title = "用户绑定店铺表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserShop sysUserShop)
    {
        List<SysUserShop> list = sysUserShopService.selectSysUserShopList(sysUserShop);
        ExcelUtil<SysUserShop> util = new ExcelUtil<SysUserShop>(SysUserShop.class);
        util.exportExcel(response, list, "用户绑定店铺表数据");
    }

    /**
     * 获取用户绑定店铺表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(sysUserShopService.selectSysUserShopById(userId));
    }

    /**
     * 新增用户绑定店铺表
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:add')")
    @Log(title = "用户绑定店铺表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserShop sysUserShop)
    {
        return toAjax(sysUserShopService.save(sysUserShop));
    }

    /**
     * 修改用户绑定店铺表
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:edit')")
    @Log(title = "用户绑定店铺表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserShop sysUserShop)
    {
        return toAjax(sysUserShopService.updateById(sysUserShop));
    }

    /**
     * 删除用户绑定店铺表
     */
    @PreAuthorize("@ss.hasPermi('system:userShop:remove')")
    @Log(title = "用户绑定店铺表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        List<String> objects = Arrays.asList(userIds);
        return toAjax(sysUserShopService.removeByIds(objects));
    }
}
